<!-- 融资金额异常-->
<template>
  <div>
    <Detail ref="detail" />
    <Ignore ref="ignore" @ok="search"/>
    <ZgNewPage
      ref="page"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="240"
      :scrollX="1500"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h,i) in headers"
          :key="`column${i}`"
          :width="h.width===0 ? 'auto' : h.width"
          :title="h.label">
          <template slot-scope="record">
            {{ record[h.code] }}
          </template>
        </a-table-column>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
import Detail from './Detail'
import Ignore from './Ignore'
export default {
  components: {
    Detail,
    Ignore
  },
  data () {
    return {
      uniqueName: 'test',
      pageOpt: {
        showPageTitle: false,
        showConditionBtn: true,
        showHeaderConfig: false,
        showAttachBtn: false
      },
      conditions: [
        { code: 'name', compType: '单行文本', label: '公司名称', defaultVal: '', extra: { placeholder: '请输入公司名称' } },
        { code: 'name1', compType: '下拉选择', label: '企业类型', defaultVal: '', extra: { 下拉选项: [{ value: '1', label: '1111' }, { value: '2', label: '2222' }] } }
      ],
      headers: [
        { code: '1', label: '融资企业', isShow: true, sort: 0, width: 200 },
        { code: '2', label: '业务编号', isShow: true, sort: 0, width: 200 },
        { code: '3', label: '授信额度', isShow: true, sort: 0, width: 200 },
        { code: '4', label: '银行额度', isShow: true, sort: 0, width: 200 },
        { code: '5', label: '预警内容', isShow: true, sort: 0, width: 200 },
        { code: '6', label: '预警时间', isShow: true, sort: 0, width: 200 },
        { code: '7', label: '处理时间', isShow: true, sort: 0, width: 200 },
        { code: '8', label: '处理结果', isShow: true, sort: 0, width: 200 }
      ],
      dataBtns: [
        { key: 1, name: '详情', type: 'link', isShow: () => { return true } },
        { key: 2, name: '更新额度', type: 'link', isShow: () => { return true } },
        { key: 3, name: '忽略', type: 'link', isShow: () => { return true } }
      ]
    }
  },
  methods: {
    search () {
      const pageRef = this.$refs.page
      if (pageRef) {
        pageRef.search()
      } else {
        setTimeout(() => {
          this.search()
        }, 50)
      }
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        { key: '1', id: '1', '1': '融资企业', '2': '91141181699136277J', '3': '2139290', '4': new Date().getTime(), '5': '授信额度不一致', '6': '2025-01-01', '7': '2025-01-01', '8': '处理结果' }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    toAdmin (opt) {
      if (opt.key === 1) {
        this.$refs.detail.open(opt.obj)
      } else if (opt.key === 2) {
         this.confirm(
          () => {},
        '即将更新当前融资申请额度，是否继续？')
      } else if (opt.key === 3) {
        this.$refs.ignore.open(opt.obj)
      }
    },
    onFilter (f, param) {
    },
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders.filter(t => {
        return t.isShow
      }).sort((a, b) => {
        return a.sort - b.sort
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
